﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DataAccess;

namespace QUANLYKHACHSAN_N4
{
    public partial class frmQuanLyKhachHang : DevComponents.DotNetBar.Office2007Form
    {
        public frmQuanLyKhachHang()
        {
            InitializeComponent();
        }

        private void frmQuanLyKhachHang_Load(object sender, EventArgs e)
        {
            XuLyDataGridView.Style(dgrDanhSach);
            tabAll_Click(null, null);

        }
        private void tabAll_Click(object sender, EventArgs e)
        {
            TabConTrol.SelectedTab = tabAll;
            dgrDanhSach.DataSource = KhachHang_Info.GetAll().Tables[0];
            tabView.Visible = false;
            TabConTrol.Height = 26;
        }
        private void tabThem_Click(object sender, EventArgs e)
        {
            txtMaKH.Enabled = true;
            tabView.Visible = false;
            TabConTrol.Height = 169;
            this.tabThem.AttachedControl = this.tabpnInfo;
            btnLamLai_Click(null, null);
            btnSua.Enabled = btnXoa.Enabled = false;
            btnThem.Enabled = true;
        }
        private void tabTimKiem_Click(object sender, EventArgs e)
        {
            tabView.Visible = false;
            TabConTrol.Height = 100;
            switch (cbChoose.SelectedIndex)
            {
                case 0:
                    dgrDanhSach.DataSource = NhanVien_Info.GetByName(txtSearch.Text);
                    break;
                case 1:
                    dgrDanhSach.DataSource = NhanVien_Info.GetByID(txtSearch.Text);
                    break;
                case 2:
                    dgrDanhSach.DataSource = NhanVien_Info.GetByCMND(txtSearch.Text);
                    break;
            }

        }
        private void tabView_Click(object sender, EventArgs e)
        {
            this.tabView.AttachedControl = this.tabpnInfo;
            tabView.Visible = true;
            TabConTrol.SelectedTab = tabView;
            TabConTrol.Height = 169;
            btnSua.Enabled = btnXoa.Enabled = true;
            btnThem.Enabled = false;
        }
        void BinGidToForm(DataGridViewRow r)
        {
            try
            {
                txtMaKH.Text = r.Cells["MAKH"].Value.ToString();
                txtHoTen.Text = r.Cells["HOVATEN"].Value.ToString();
                txtCMND.Text = r.Cells["CMND"].Value.ToString();
                txtPassport.Text = r.Cells["PASSPORT"].Value.ToString();
                txtEmail.Text = r.Cells["EMAIL"].Value.ToString();
                txtDienThoai.Text = r.Cells["DIENTHOAI"].Value.ToString();
                txtDiaChi.Text = r.Cells["DIACHI"].Value.ToString();
                txtCoQuan.Text = r.Cells["COQUAN"].Value.ToString();
                cbGioiTinh.Text = Convert.ToBoolean(r.Cells["GIOITINH"].Value) ? "Nam" : "Nữ";
            }
            catch (Exception)
            {
            }
        }
        private void btnLamLai_Click(object sender, EventArgs e)
        {
            try
            {

                if (!tabView.Visible)
                {
                    txtMaKH.Text =
                    txtHoTen.Text =
                    txtCMND.Text =
                    txtPassport.Text =
                    txtEmail.Text =
                    txtDienThoai.Text =
                    txtDiaChi.Text =
                    txtCoQuan.Text = "";
                    cbGioiTinh.Text = "Nam";
                }
                else
                    BinGidToForm(dgrDanhSach.CurrentRow);
            }
            catch (Exception)
            {
            }
        }
        private void dgrDanhSach_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            try
            {
                txtMaKH.Enabled = false;
                BinGidToForm(dgrDanhSach.CurrentRow);
                tabView_Click(null, null);
            }
            catch (Exception)
            {
            }
        }
        private void btnThem_Click(object sender, EventArgs e)
        {
            if (KhachHang_Info.Add(txtMaKH.Text, txtHoTen.Text, int.Parse(txtCMND.Text), txtPassport.Text, txtEmail.Text, txtDienThoai.Text, txtDiaChi.Text, txtCoQuan.Text, cbGioiTinh.Text == "Nam"))
            {
                BatLoi.ThongBao("Thêm Khách Hàng Thành Công");
                tabAll_Click(null, null);
            }

        }
        private void btnXoa_Click(object sender, EventArgs e)
        {
            //if (NhanVien_Info.Delete(txtMaNV.Text))
            //{
            //    BatLoi.ThongBao("Xóa Nhân Viên Thành Công");
            //    tabAll_Click(null, null);
            //}
        }
        private void btnSua_Click(object sender, EventArgs e)
        {
            //if (NhanVien_Info.Update(txtMaNV.Text, txtHoTen.Text, dtpNgaySinh.Value, txtDiaChi.Text, txtDienThoai.Text, int.Parse(txtCMND.Text), cbGioiTinh.Text == "Nam", cbChucVu.Text))
            //{
            //    BatLoi.ThongBao("Update Nhân Viên Thành Công");
            //    tabAll_Click(null, null);
            //}
        }

        private void btnXoaSelectItem_Click(object sender, EventArgs e)
        {
            //if (BatLoi.DgResult("Bạn có muốn xóa những nhân viên được chọn"))
            //{
            //    foreach (DataGridViewRow r in dgrDanhSach.SelectedRows)
            //        NhanVien_Info.Delete(r.Cells["manv"].Value.ToString());
            //}
        }


        private void btnInAn_Click(object sender, EventArgs e)
        {
            try
            {

                frmFormMain frm = MdiParent as frmFormMain;
                frm.pr = new frmPrint();
                DuLieuRP.SetKhungPrint(frm.pr, "ds_KhachHang_GetID", frm.pr.KhachHangBindingSource);
                frm.pr.rpViewer.LocalReport.ReportEmbeddedResource = "QUANLYKHACHSAN_N4.REPORT.rpThongTinKhachHang.rdlc";
                frm.pr.KhachHangBindingSource.DataSource = KhachHang_Info.GetByID(txtMaKH.Text).Tables[0];
                frm.pr.rpViewer.RefreshReport();
                frm.pr.Text = "THÔNG TIN KHÁCH HÀNG " + txtHoTen.Text;
                frm.ShowPrint();
            }
            catch (Exception)
            {

            }
        }
    }
}
